
layui.use(['jquery','index','echarts'], function () {
    var $=layui.jquery;
    $("#mainchart").css("height",window.innerHeight-100+'px')
    let myChart = layui.echarts.init(document.getElementById('mainchart'));

    myChart.setOption({
        color: ['#009688','#2f4554', '#61a0a8'],
        title: {
            text: doHandleMonth() + '月'
        },
        tooltip: {},
        legend: {
            data: ['外销','出货']
        },
        xAxis: {
            type: "value",
            boundaryGap: [0, 0.01]
        },
        yAxis: {
            type: "category",
            data: []

        },
        series: [{
            name: '外销',
            type: 'bar',
            itemStyle:{
                normal:{
                    label: {
                        show: true,
                        position: 'inside',
                        textStyle:{
                            color:"black",
                            fontSize:14
                        }
                    },
                }
            },

            data: []
        },
            {
                name: '出货',
                type: 'bar',
                itemStyle:{
                    normal:{
                        label: {
                            show: true,
                            position: 'inside',
                            textStyle:{
                                color:"white",
                                fontSize:14
                            }
                        },
                    }
                },

                data: []
            }]
    });

    myChart.showLoading({text: '数据正在加载中...'  });

    setTimeout(function(){
        $.ajax({
            url:"carryDetail/statistics/statisticsChartInfo",
            success:function(jsonData){
                myChart.setOption({
                    color: ['#009688','#2f4554', '#61a0a8'],
                    title: {
                        text: doHandleMonth() + '月'
                    },
                    tooltip: {},
                    legend: {
                        data: ['外销','出货']
                    },
                    xAxis: {
                        type: "value",
                        boundaryGap: [0, 0.01]
                    },
                    yAxis: {
                        type: "category",
                        data: jsonData.data.yAxisData

                    },
                    series: [{
                        name: '外销',
                        type: 'bar',
                        itemStyle:{
                            normal:{
                                label: {
                                    show: true,
                                    position: 'inside',
                                    textStyle:{
                                        color:"black",
                                        fontSize:14
                                    }
                                },
                            }
                        },

                        data: jsonData.data.exportData.sort(function (a, b) { return a.value - b.value; }),
                    },
                        {
                            name: '出货',
                            type: 'bar',
                            itemStyle:{
                                normal:{
                                    label: {
                                        show: true,
                                        position: 'inside',
                                        textStyle:{
                                            color:"white",
                                            fontSize:14
                                        }
                                    },
                                }
                            },

                            data: jsonData.data.detailData.sort(function (a, b) { return a.value - b.value; }),
                        }]
                });
                // 设置加载等待隐藏
                myChart.hideLoading();
            }
        });
    },1000);


    //获取当前月份
    function doHandleMonth() {
        let myDate = new Date();
        let tMonth = myDate.getMonth();
        let m = tMonth + 1;
        if (m.toString().length == 1) {
            m = "0" + m;
        }
        return m;
    }


});